# 根据字典值的大小对字典排序
dict_old = {'lilei': 34, 'wangfei': 94, 'fengtian': 88}
# 方法1
tuple_new = ((v, k) for k, v in dict_old.items())
tuple_new = sorted(tuple_new)  # 基于元组可以直接比较大小
print(tuple_new)
dict_new = {i[1]: i[0] for i in tuple_new}
print(dict_old)
print(dict_new)
# 方法2
tuple_new = sorted(dict_old.items(), key=lambda item: item[1])
dict_new = {i[0]: i[1] for i in tuple_new}
print(dict_old)
print(dict_new)
